{extend name=".././view/create.html" /}
{block name="form"}
<form class="layui-form layui-form-pane" lay-filter="myform">
	<div class="layui-form-item" style="text-align: left;">
		<button type="button" class="layui-btn" onclick="checkAll()">
			{$list.set.butname}
		</button>
	</div>
	<table class="layui-table">
		<colgroup>
			<col width="10px">
			<col width="200px">
			<col width="80px">
			<col>
			<col>
		</colgroup>
		<thead>
			<tr>
				<th>序号</th>
				<th>统计项目</th>
				<th>统计开关</th>
				<th>统计状态</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			{volist name="$list['tjxm']" id="vo"}
			<tr>
				<td>{$i}</td>
				<td>{$vo.title}</td>
				<td>
					<input type="checkbox" name="tj" lay-skin="switch" lay-text="开启|关闭" {$vo.checked}>
				</td>
				<td id="showtd{$i}">等待统计</i></td>
				<td><a href="javascript:;" title="统计" onclick="tongji(this)" url="{$vo.url}" val="{$i}"><i class="layui-icon layui-icon-form"></i></a></td>
			</tr>
			{/volist}
		</tbody>
	</table>
</form>
{/block}
{block name="myjs"}
<script>
function checkAll() {
	var inputs;
	inputs = $(":checked");
	tongjiAll(inputs);
	return false;
}

function tongjiAll(inputs, xiabiao=0) {
	cnt = inputs.length - 1;
	obj = inputs[xiabiao];
	obj = $(obj).parents("tr").children().last().find("a");
	var data;
	data = {
		'kaoshi_id': "{$list.set.kaoshi_id}"
	}
	var url;
	url = obj.attr('url');
	var val;
	val = $(obj).attr('val');

	// 到服务器去删除数据。
	$.ajax({
		url: url,
		type: 'POST',
		async: true,
		data: data,
		beforeSend: function() {
			$('#showtd' + val).text('正在统计');
			$('#showtd' + val).append("<i class='layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop'>");
		},
		complete: function() {
			$('#showtd' + val).children("i").remove();
		},
		success: function(result) {
			$('#showtd' + val).text(result.msg);
			
			if(xiabiao >= 0 && xiabiao < cnt)
			{
				tongjiAll(inputs, xiabiao + 1);
			}
		},
		error: function(result) {
			$('#showtd' + val).text(result.msg);
		},
	});
}

function tongji(obj) {
	var data;
	data = {
		'kaoshi_id': "{$list.set.kaoshi_id}"
	}
	var url;
	url = $(obj).attr('url');
	var val;
	val = $(obj).attr('val');

	// 到服务器去删除数据。
	$.ajax({
		url: url,
		type: 'POST',
		async: true,
		data: data,
		beforeSend: function() {
			$('#showtd' + val).text('正在统计');
			$('#showtd' + val).append("<i class='layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop'>");
		},
		complete: function() {
			$('#showtd' + val).children("i").remove();
		},
		success: function(result) {
			$('#showtd' + val).text(result.msg);
		},
		error: function(result) {
			$('#showtd' + val).text(result.msg);
		},
	});
}


</script>
{/block}